﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Database;
using Business;

namespace DT5_Anh09110006_Hung09110044_Vu09110157.Admin
{
    public partial class QuanLyNguoiDung : System.Web.UI.Page
    {
        Business.QuanLyNguoiDung qlNguoiDung = new Business.QuanLyNguoiDung();
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack){
                LoadDuLieu();
            }
        }

        private void LoadDuLieu(){
            grvQLNguoiDung.DataSource = qlNguoiDung.LayDanhSachNguoiDung();
            grvQLNguoiDung.DataBind();
        }
        protected void grvQLNguoiDung_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            grvQLNguoiDung.PageIndex = e.NewPageIndex;
            LoadDuLieu();
        }

        protected void grvQLNguoiDung_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName.Equals("Xoa"))
            {
                if (qlNguoiDung.XoaNguoiDung(e.CommandArgument.ToString()))
                {
                    LoadDuLieu();
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "redirectMe", "alert('Không thể xóa người dùng này');", true);
                }
            }
        }

        protected void btnThemND_Click(object sender, EventArgs e)
        {
            Response.Redirect("ThemNguoiDung.aspx");
        }
    }
}